from src.application.payment.dto import NewBillDTO
from src.infrastructure.payment_client.api import PaymentAPIImpl


class PayPalychClient(PaymentAPIImpl):
    def __init__(self, api_token: str, shop_id: str):
        super().__init__(api_token, shop_id, base_url="https://paypalych.com/api/v1")

    async def create_bill(self, amount: float, order_id: int, currency_in: str = "RUB"):
        """Create New Bill

        POST https://paypalych.com/api/v1/bill/create

        https://paypalych.com/en/merchant/api#bill-create

        """

        bill = NewBillDTO(
            amount=amount,
            order_id=order_id,
            shop_id=self.shop_id,
            currency_in=currency_in,
        )

        return await self.send_signed_request("POST", "/bill/create", bill.__dict__)

    async def get_bill(self, bill_id: str):
        """Query Bill

        GET https://paypalych.com/api/v1/bill/status

        https://paypalych.com/en/merchant/api#bill-status

        """

        payload = {
            "id": bill_id,
        }

        return await self.send_signed_request("GET", "/bill/status", payload)

    async def get_bills(self):
        """Activate/Deactivate Bill

        POST https://paypalych.com/api/v1/bill/toggle_activity

        https://paypalych.com/en/merchant/api#bill-toggle

        """

        payload = {
            "shop_id": self.shop_id,
        }

        return await self.send_signed_request("GET", "/bill/search", payload)

    async def get_merchant_balance(self):
        """Get Wallet Balance

        GET https://paypalych.com/api/v1/merchant/balance

        https://paypalych.com/en/merchant/api#merchant-balance

        """

        return await self.send_signed_request("GET", "/merchant/balance")
